/*
**  Copyright (c) 2014 Michael Liu(michael.liu.point@gmail.com).
**
**  Project: Gateway Unified Management Platform
**  File:    dprule.h
**  Author:  Michael
**  Date:    06/24/2014
**
**  Purpose:
**    data path rules defines.
*/

#ifndef __DATAPATH_RULE_MGR_H__
#define __DATAPATH_RULE_MGR_H__

#ifdef __cplusplus
extern "C" {
#endif				/* __cplusplus */

/* Include files. */

#include "common.h"
#include "cmrc.h"
#include "list.h"
#include "dpdev.h"

/* Macro constant definitions. */

#define DNS_REDIRECT_URL_SIZE		(128)

/* Type definitions. */

	enum {
		eIPT_RULE_TABLE_FILTER,
		eIPT_RULE_TABLE_NAT,
		eIPT_RULE_TABLE_MANGLE,
		eIPT_RULE_TABLE_RAW,
		eIPT_RULE_TABLE_MAX,
	} eipt_rule_table;

	typedef struct dp_ipt_rule_entry tdp_ipt_rule_entry;
	typedef e_ret(*update_rule) (char *rule_buf, const tdp_ipt_rule_entry * entry);

	struct dp_ipt_rule_entry {
		struct list_head list;
		char *ipt_rule;
		update_rule update;
	};

	typedef struct dp_ipt_rule_list tdp_ipt_rule_list;
	struct dp_ipt_rule_list {
		struct list_head tables[eIPT_RULE_TABLE_MAX];
	};

	typedef struct dp_rule tdp_rule;
	struct dp_rule {
		tdp_ipt_rule_list ipt_rule;
		char mgr_url[DNS_REDIRECT_URL_SIZE];
	};

/* External function declarations. */

	extern e_ret dp_rules_add_ipt_rule(tdata_paths * dp, unsigned char table, const char *rule, update_rule update);
	extern e_ret dp_rules_del_ipt_rule(tdata_paths * dp, unsigned char table, const char *rule);
	extern e_ret dp_rules_apply_ipt_rule(tdata_paths * dp);

/* Macro API definitions. */

/* Global variable declarations. */

#ifdef __cplusplus
}				/* extern "C" */
#endif				/* __cplusplus */
#endif				/* __DATAPATH_RULE_MGR_H__ */
